
package com.zdxlz.fcmp.business.controller.local;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdxlz.fcmp.business.dto.ict.TicketInfoDto;
import com.zdxlz.fcmp.business.entity.TicketInfoEntity;
import com.zdxlz.fcmp.business.service.ITicketInfoService;
import com.zdxlz.fcmp.common.core.util.R;
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zdxlz.fcmp.common.core.constant.CommonConstants.CREATE_SUCCESS;
import static com.zdxlz.fcmp.common.core.constant.CommonConstants.OPERATION_SUCCESS;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author: aman
 * @since 2025-01-30
 */
@RestController
@RequestMapping("/api/v1/ticket")
@AllArgsConstructor
public class TicketInfoController {

    private ITicketInfoService ticketInfoService;

    @GetMapping
    public R getList(@ParameterObject Page<TicketInfoEntity> page, @ParameterObject TicketInfoDto ticketInfoDto) {
        return R.ok(ticketInfoService.getList(page, ticketInfoDto), OPERATION_SUCCESS);
    }

    @GetMapping("/{id}")
    public TicketInfoEntity getById(@PathVariable Long id) {
        return ticketInfoService.getById(id);
    }

    @PostMapping
    public R create(@RequestBody TicketInfoDto ticketInfoDto) {
        return R.ok(ticketInfoService.createTicketInfo(ticketInfoDto), CREATE_SUCCESS);
    }

    @PutMapping("/{id}")
    public boolean update(@PathVariable Integer id, @RequestBody TicketInfoEntity entity) {
        entity.setId(id);
        return ticketInfoService.updateById(entity);
    }

    @DeleteMapping
    public boolean delete(@RequestBody List<Integer> ids) {
        return ticketInfoService.removeBatchByIds(ids);
    }

}
